package com.xyzh05.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

@Entity
@Table(name="notepad")
@Searchable
@XmlRootElement
public class Notepad extends BaseObject implements Serializable {
	
	public static final Short SIGN = 21;
	public static final Short NOTE = 22;

	public static final Short PERIOD_DEFAULT = 0;
	public static final Short PERIOD_MORNING = 1;
	public static final Short PERIOD_AM = 2;
	public static final Short PERIOD_NOON = 3;
	public static final Short PERIOD_PM = 4;
	public static final Short PERIOD_NIGHT = 5;
	public static final Short PERIOD_EVENING = 6;
	
    private Long id;
    private DictItem dictItem;
    private User user;
    private Date signInTime;
    private Date signOutTime;
    private String content;
    private Short mode;
    private Short period = PERIOD_DEFAULT;
    private Short level = 0;
    private Short type;
    private String location;
    private String longitude;
    private String latitude;
    private Set<Comment> comments = new HashSet<Comment>(0);

    @Id @GeneratedValue(strategy=GenerationType.AUTO) @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="note_type_id", nullable=false)
    public DictItem getDictItem() {
        return this.dictItem;
    }
    
    public void setDictItem(DictItem dictItem) {
        this.dictItem = dictItem;
    }

    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="user_id")
    public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Temporal(TemporalType.TIMESTAMP)
    @Column(name="sign_in_time", nullable=false, length=19)
    @SearchableProperty
    public Date getSignInTime() {
        return this.signInTime;
    }
    
    public void setSignInTime(Date signInTime) {
        this.signInTime = signInTime;
    }
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="sign_out_time", length=19)
    @SearchableProperty
    public Date getSignOutTime() {
        return this.signOutTime;
    }
    
    public void setSignOutTime(Date signOutTime) {
        this.signOutTime = signOutTime;
    }
    
    @Column(name="content", nullable=false, length=512)
    @SearchableProperty
    public String getContent() {
        return this.content;
    }
    
    public void setContent(String content) {
        this.content = content;
    }
    
    @Column(name="mode", nullable=false)
    @SearchableProperty
    public Short getMode() {
        return this.mode;
    }
    
    public void setMode(Short mode) {
        this.mode = mode;
    }
    
    @Column(name="period", nullable=false)
    @SearchableProperty
    public Short getPeriod() {
        return this.period;
    }
    
    public void setPeriod(Short period) {
        this.period = period;
    }
    
    @Column(name="type", nullable=false)
    @SearchableProperty
    public Short getType() {
        return this.type;
    }
    
    public void setType(Short type) {
        this.type = type;
    }
    
    @Column(name="level", nullable=false)
    @SearchableProperty
    public Short getLevel() {
        return this.level;
    }
    
    public void setLevel(Short level) {
        this.level = level;
    }
    
    @Column(name="location")
    @SearchableProperty
    public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

    @Column(name="longitude")
    @SearchableProperty
	public String getLongitude() {
		return longitude;
	}

	public void setLongitude(String longitude) {
		this.longitude = longitude;
	}

    @Column(name="latitude")
    @SearchableProperty
	public String getLatitude() {
		return latitude;
	}

	public void setLatitude(String latitude) {
		this.latitude = latitude;
	}

	@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="notepad")
    public Set<Comment> getComments() {
        return this.comments;
    }
    
    public void setComments(Set<Comment> comments) {
        this.comments = comments;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Notepad pojo = (Notepad) o;

        if (dictItem != null ? !dictItem.equals(pojo.dictItem) : pojo.dictItem != null) return false;
        if (user != null ? !user.equals(pojo.user) : pojo.user != null) return false;
        if (signInTime != null ? !signInTime.equals(pojo.signInTime) : pojo.signInTime != null) return false;
        if (signOutTime != null ? !signOutTime.equals(pojo.signOutTime) : pojo.signOutTime != null) return false;
        if (content != null ? !content.equals(pojo.content) : pojo.content != null) return false;
        if (mode != null ? !mode.equals(pojo.mode) : pojo.mode != null) return false;
        if (period != null ? !period.equals(pojo.period) : pojo.period != null) return false;
        if (level != null ? !level.equals(pojo.level) : pojo.level != null) return false;
        if (type != null ? !type.equals(pojo.type) : pojo.type != null) return false;
        if (location != null ? !location.equals(pojo.location) : pojo.location != null) return false;
        if (longitude != null ? !longitude.equals(pojo.longitude) : pojo.longitude != null) return false;
        if (latitude != null ? !latitude.equals(pojo.latitude) : pojo.latitude != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (dictItem != null ? dictItem.hashCode() : 0);
        result = 31 * result + (user != null ? user.hashCode() : 0);
        result = 31 * result + (signInTime != null ? signInTime.hashCode() : 0);
        result = 31 * result + (signOutTime != null ? signOutTime.hashCode() : 0);
        result = 31 * result + (content != null ? content.hashCode() : 0);
        result = 31 * result + (mode != null ? mode.hashCode() : 0);
        result = 31 * result + (period != null ? period.hashCode() : 0);
        result = 31 * result + (level != null ? level.hashCode() : 0);
        result = 31 * result + (type != null ? type.hashCode() : 0);
        result = 31 * result + (location != null ? location.hashCode() : 0);
        result = 31 * result + (longitude != null ? longitude.hashCode() : 0);
        result = 31 * result + (latitude != null ? latitude.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("dictItem").append("='").append(getDictItem()).append("', ");
        sb.append("user").append("='").append(getUser()).append("', ");
        sb.append("signInTime").append("='").append(getSignInTime()).append("', ");
        sb.append("signOutTime").append("='").append(getSignOutTime()).append("', ");
        sb.append("content").append("='").append(getContent()).append("', ");
        sb.append("mode").append("='").append(getMode()).append("', ");
        sb.append("period").append("='").append(getPeriod()).append("', ");
        sb.append("level").append("='").append(getLevel()).append("', ");
        sb.append("type").append("='").append(getType()).append("', ");
        sb.append("location").append("='").append(getLocation()).append("', ");
        sb.append("longitude").append("='").append(getLongitude()).append("', ");
        sb.append("latitude").append("='").append(getLatitude()).append("', ");
        
        sb.append("]");
      
        return sb.toString();
    }

}
